<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>新增党政建设</title>
    <script type="text/javascript" src="assets/dwz/ui/uploadify/scripts/jquery.uploadify.js"></script>
    <script type="text/javascript">
      $(function(){
        //初始化uploadify 用于word上传
        $("#uploadFile").uploadify({
          'swf' : 'assets/dwz/ui/uploadify/scripts/uploadify.swf',//上传的flash文件,必用
          'uploader' : 'community_image_service',//上传的请求URL
          'method' : "get",//请求方式
          'fileObjName' : 'fileName',//与后台Action中file属性一样
          'formData' : {
            'uploadUrl' : 'hangzhou/talent'
          },//附带值，参数
          'auto' : true,//自动上传
          'multi' : false,//是否为多文件上传
          'buttonImage':'assets/dwz/ui/uploadify/img/upload.png',
          'uploadLimit' : 111111,//一次可以上传多少个文件
          'fileSizeLimit' : '100000KB',//单个文件上传最大值
          'queueSizeLimit' : 100,//最多上传个数
          'successTimeout' : 99999,//上传超时时间
          'rollover' : true,
          'dataType':'text',
          'removeCompleted' : true,//上传完成后是否自动隐藏进度条
          onUploadSuccess : function(file,//每个文件上传完成后都会调用一次，其中data为，相应信息，file为上传文件信息,response只有两个值true or false
                                     data, response) {
              if( data == null ){
                  alertErrorMessage("上传图片失败");
                  return;
              }
              alertOkMessage( "上传成功！" );
              $(".add-partyBuilding-form img").attr("src",data);
              $(".add-partyBuilding-form input[name='imageUrl']").val(data);
          },
          onError : function() {
            alert("上传失败");
          }
        });
      })

      //全选/取消全选
      function checkedAllBlock(){
        var objChecked = $( ".add-partyBuilding-form" ).find( "input[name='checkedAll']" ).attr( "checked" );
        if( objChecked == "checked" ){
          $(".add-partyBuilding-form").find( "input[name='blockIds']").each(function(i,j){
            $(j).attr( "checked","checked" );
          })
        }else{
          $(".add-partyBuilding-form").find( "input[name='blockIds']").each(function(i,j){
            $(j).removeAttr( "checked" );
          })
        }
      }

      //提交表单校验
      function checkAddPartyBuilding(){
        var id = "";
        $(".add_community_partyBuilding_form").find( "input[name='blockIds']:checked").each(function(i,j){
            id += $(j).val() + ",";
        })
        if( id == "" ){
          alertMsg.warn('请选择小区！')
          return false;
        }
          id = id.substring( 0,id.length - 1 );
        var guideId = $(".add_community_partyBuilding_form").find( "select[name='guideId']").val();
        if( guideId == -1 ){
          alertMsg.warn('请选择党政建设！')
          return false;
        }

        var imageUrl = $(".add_community_partyBuilding_form").find( "input[name='imageUrl']").val();
        if( imageUrl == "http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg" || imageUrl == null || imageUrl == "" ){
          alertMsg.warn('请上传封面！')
          return false;
        }

        $(".add_community_partyBuilding_form").find( "input[name='blockIdStr']").val( id );
        $(".add_community_partyBuilding_form").submit();
        return true;
      }

      //错误提示
      function alertErrorMessage(word){
          alertMsg.error(word);
      }

      //成功提示
      function alertOkMessage(word){
          alertMsg.correct(word);
      }

      //删除图片
      $(".add-partyBuilding-form .delete-this-pic").click(function () {
          $(".add-partyBuilding-form img").attr("src","http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg");
          $(".add-partyBuilding-form input[name='imageUrl']").val("");
      })
  </script>
  </head>
  <body>
    <div class="page unitBox">
      <form method="post" action="save_add_community_partyBuilding" class="pageForm required-validate add_community_partyBuilding_form" onsubmit="return validateCallback(this, dialogAjaxDone)" novalidate="novalidate">
        <div class="pageContent">
          <div class="pageFormContent add-partyBuilding-form" layouth="97">
            <dl>
              <dt>标题：</dt>
              <dd>
                <input type="text" maxlength="20" placeholder="最多只能输入20个汉字" name="buildTitle" class="required"/>
              </dd>
            </dl>
            <dl style="height: 110px;">
              <dt>图片logo：</dt>
              <dd style="position:relative;">
                <%--<img src="../assets/dwz/ui/images/community-upload-fengmian.png" width="120px;" height="80px;"/>--%>
                <img src="http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg" width="120px;" height="80px;"/>
                <input type="file" name="file" id="uploadFile" />
                <input type="hidden" name="imageUrl" value="http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg"/>
                <a style="background: rgba(0,0,0,0.5);display:block;position:absolute;top:0;left:86px;padding:5px;text-align: center;color:#fff;" class="delete-this-pic">删除</a>
              </dd>
            </dl>
            <dl style="height: 110px;">
              <dt>指南内容：</dt>
              <dd>
                <textarea placeholder="最多只能输入500个汉字" name="buildContent" class="required" cols="35" rows="5"></textarea>
              </dd>
            </dl>
            <dl style="height: auto;">
              <dt>所属小区：</dt>
              <dd>
                <input type="hidden" name="blockIdStr"/>
                <input type="checkbox" name="checkedAll" onclick="checkedAllBlock();"/>全选<br>
                <c:forEach var="block" items="${blocks}">
                  <input type="checkbox" value="${block.id}" name="blockIds"/>${block.blockName}<br>
                </c:forEach>
              </dd>
            </dl>
          </div>
          <div class="formBar">
            <ul>
              <li>
                <div class="buttonActive">
                  <div class="buttonContent">
                    <button type="button" onclick="return checkAddPartyBuilding();">保存</button>
                  </div>
                </div>
              </li>
              <li>
                <div class="button">
                  <div class="buttonContent">
                    <button class="close" type="button">关闭</button>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </form>
    </div>
  </body>
</html>
